package top.withwings.bonus.bonus.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.withwings.bonus.bonus.pojo.FinalBonus;
import top.withwings.bonus.bonus.service.BonusComputationService;
import top.withwings.bonus.bonus.service.FinalBonusService;
import top.withwings.bonus.common.service.UserService;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("final")
public class FinalBonusController {

    @Autowired private BonusComputationService bonusComputationService;

    @Autowired private FinalBonusService finalBonusService;

    @Autowired private UserService userService;

    @PostMapping("compute")
    public void compute(String yearMonth){
        bonusComputationService.computeSingleBonus(yearMonth);
        bonusComputationService.computeFinalBonus(yearMonth);
    }

    @PostMapping("list")
    public List<FinalBonus> list(String yearMonth){

        return finalBonusService.listBySalesman(yearMonth);
    }


    @PostMapping("history")
    public List<FinalBonus> history(int salesmanId){

        return finalBonusService.history(userService.findById(salesmanId));

    }

}
